package edu.visualizetion.info.sensorcollection;

import java.io.FileNotFoundException;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Server {

	public static void main(String[] args) {

		if (args.length != 1) {
			System.out.println("Please the config dir path");
			return;
		}
		String libPath = args[0];
		ClassPathUtils classPathUtils = new ClassPathUtils();
		try {
			classPathUtils.addLibToClassPath(libPath);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return;
		}
		IService service;
		try {
			service = new ServiceImpl();
		} catch (RemoteException e) {
			e.printStackTrace();
			return;
		}
		int port = Registry.REGISTRY_PORT;
		try {
			LocateRegistry.createRegistry(port);
			Registry registry = LocateRegistry.getRegistry(port);
			registry.bind("iService", service);
			System.out
					.println("bind successfully the address is " + service.getServiceName() + ", the port is " + port);
		} catch (RemoteException e) {
			e.printStackTrace();
			return;
		} catch (AlreadyBoundException e) {
			e.printStackTrace();
		} 
	}
}
